public class Solution275 {
    public int hIndex(int[] citations) {
        int l=1,r=citations.length;
        int ans=0;
        while (l<=r){
            int mid=(l+r)/2;
            if (citations[citations.length-mid]>=mid){
                ans=mid;
                l=mid+1;
            }else{
                r=mid-1;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution275().hIndex(new int[]{0,1,3,5,6}));
    }
}
